// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2022 Ivan Baidakou

#pragma once

#include "definitions.hpp"
#include "message.hpp"

namespace rotor_light::message {

/** \struct ChangeState
 *  \brief State Change command, from supervisor/actor to actor
 */
struct ChangeState : Message {
  /** synthethic message id used as anchor for rotor-light messages */
  static constexpr auto undef = std::numeric_limits<MessageTypeId>::max();

  /** message type identifyer */
  static constexpr auto type_id = undef - 1;

  /** records destination and state change command */
  ChangeState(ActorId to, details::StateCommand command_, bool success_)
      : Message(to), command{command_}, success{success_} {}

  /** state change command */
  details::StateCommand command;

  /** success marker */
  bool success;
};

/** \struct ChangeStateAck
 *  \brief State Change confirmation, from actor to supervisor
 */
struct ChangeStateAck : Message {
  /** message type identifyer */
  static constexpr auto type_id = ChangeState::type_id - 1;

  /** records origin of the state change and success marker */
  ChangeStateAck(ActorId to, ActorId from_, State state_, bool success_)
      : Message(to), from{from_}, state{state_}, success{success_} {}

  /** origin/source actor */
  ActorId from;

  /** asked/subject state */
  State state;

  /** success marker */
  bool success;
};

/** \struct RefreshTime
 *  \brief Idle message, refreshes time and triggers expired timers
 */
struct RefreshTime : Message {
  /** message type identifyer */
  static constexpr auto type_id = ChangeStateAck::type_id - 1;

  /** use parent's ctor */
  using Message::Message;
};

} // namespace rotor_light::message
